import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_crud_test_amir_rabbani/core/resource/my_colors.dart';
import 'package:flutter_crud_test_amir_rabbani/core/resource/typography.dart';

class ThemeConfig {
  static const fontName = 'vazirmatn';

  static ThemeData createTheme({
    required Brightness brightness,
    required Color background,
    required Color primaryText,
    required Color secondaryText,
    required Color accentColor,
    required Color divider,
    required Color buttonBackground,
    required Color buttonText,
    required Color cardBackground,
    required Color disabled,
    required Color error,
    required Color textButtonColor,
    required Color hintColor,
    required Color checkBoxColor,
    required Color iconColor,
    required Color textFieldBorderColor,
    required Color activeTextTabColor,
    required Color deActiveTextTabColor,
    required Color indicatorTabColor,
  }) {
    final baseTextTheme = brightness == Brightness.dark
        ? Typography.blackMountainView
        : Typography.whiteMountainView;

    return ThemeData(
      useMaterial3: true,
      fontFamily: ThemeConfig.fontName,
      primarySwatch: CustomColors.primary,
      brightness: brightness,
      canvasColor: background,
      cardColor: cardBackground,

      scaffoldBackgroundColor: background,
      dividerColor: divider,
      textSelectionTheme: const TextSelectionThemeData(
        cursorColor: CustomColors.primary,
      ),
      elevatedButtonTheme: ElevatedButtonThemeData(
        style: ElevatedButton.styleFrom(
          // backgroundColor: MyColors.primary,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(10),
          ),
        ),
      ),
      dividerTheme: DividerThemeData(
        color: divider,
        space: 1,
        thickness: 1,
      ),
      cardTheme: CardTheme(
        color: cardBackground,
        margin: EdgeInsets.zero,
        clipBehavior: Clip.antiAliasWithSaveLayer,
      ),
      checkboxTheme: CheckboxThemeData(
        side: WidgetStateBorderSide.resolveWith((states) => BorderSide.none),
        checkColor: WidgetStateProperty.all<Color>(checkBoxColor),
        fillColor: WidgetStateProperty.all<Color>(CustomColors.primary),
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(2),
        ),
      ),
      tabBarTheme: TabBarTheme(
          labelColor: activeTextTabColor,
          unselectedLabelStyle: TextStyle(
              fontWeight: FontWeight.w600,
              fontSize: 18.0,
              color: primaryText,
              fontFamily: ThemeConfig.fontName),
          labelStyle: TextStyle(
              fontWeight: FontWeight.w600,
              fontSize: 18.0,
              color: primaryText,
              fontFamily: ThemeConfig.fontName), // color for text
          indicator: UnderlineTabIndicator(
              borderSide: BorderSide(color: indicatorTabColor))),
      // backgroundColor: background,
      primaryColor: accentColor,
      // accentColor: accentColor,
      // toggleableActiveColor: accentColor,
      appBarTheme: AppBarTheme(
        // brightness: brightness,
        // color: background,
        surfaceTintColor: background,
        foregroundColor: background,
        backgroundColor: background,
        iconTheme: IconThemeData(
          size: 20,
          color: iconColor,
        ),
        titleTextStyle: CustomTextStyle.titleMedium.copyWith(
          color: primaryText,
          fontFamily: fontName,
          letterSpacing: 0,
        ),
      ),
      iconTheme: IconThemeData(
        color: iconColor,
        size: 16.0,
      ),
      // errorColor: error,
      buttonTheme: ButtonThemeData(
        buttonColor: buttonBackground,
        textTheme: ButtonTextTheme.primary,
        colorScheme: ColorScheme(
          brightness: brightness,
          primary: accentColor,
          // primaryVariant: accentColor,
          secondary: accentColor,
          outline: textFieldBorderColor,
          // secondaryVariant: accentColor,
          surface: background,
          error: error,
          onPrimary: buttonText,
          onSecondary: buttonText,
          onSurface: buttonText,
          onError: buttonText,
        ),
        padding: const EdgeInsets.all(16.0),
      ),
      textButtonTheme: TextButtonThemeData(
        style: TextButton.styleFrom(
            textStyle: baseTextTheme.headlineSmall!.copyWith(
          color: primaryText,
          fontFamily: ThemeConfig.fontName,
          letterSpacing: 0,
        )),
      ),
      cupertinoOverrideTheme: CupertinoThemeData(
        brightness: brightness,
        primaryColor: accentColor,
      ),
      inputDecorationTheme: InputDecorationTheme(
        errorStyle: TextStyle(color: error),
        labelStyle: TextStyle(
            fontWeight: FontWeight.w600,
            fontSize: 16.0,
            color: primaryText,
            fontFamily: ThemeConfig.fontName),
        hintStyle: TextStyle(
          color: hintColor,
          fontSize: 13.0,
          fontWeight: FontWeight.w300,
          fontFamily: ThemeConfig.fontName,
        ),
        contentPadding: const EdgeInsets.all(0),
        fillColor: cardBackground,
        filled: true,
        border: OutlineInputBorder(
            borderRadius: BorderRadius.circular(10),
            borderSide: BorderSide(color: textFieldBorderColor)),
      ),
      textTheme: TextTheme(
        ///Title
        titleLarge: CustomTextStyle.titleLarge,
        titleMedium: CustomTextStyle.titleMedium,
        titleSmall: CustomTextStyle.titleSmall,

        ///Label
        labelLarge: CustomTextStyle.labelLarge,
        labelMedium: CustomTextStyle.labelMedium,
        labelSmall: CustomTextStyle.labelSmall,

        ///body
        bodyLarge: CustomTextStyle.bodyLarge,
        bodyMedium: CustomTextStyle.bodyMedium,
        bodySmall: CustomTextStyle.bodySmall,

        ///Display
        displaySmall: CustomTextStyle.displaySmall,
        displayLarge: CustomTextStyle.displayLarge,
        displayMedium: CustomTextStyle.displayMedium,

        ///Headline
        headlineSmall: CustomTextStyle.headlineSmall,
        headlineMedium: CustomTextStyle.headlineMedium,
        headlineLarge: CustomTextStyle.headlineLarge,
      ),
    );
  }

  static ThemeData get lightTheme => createTheme(
        brightness: Brightness.light,
        background: CustomColors.primaryBackground,
        cardBackground: CustomColors.secondaryBackground,
        primaryText: CustomColors.primaryText,
        secondaryText: CustomColors.secondaryText,
        accentColor: CustomColors.primary,
        divider: CustomColors.secondaryText,
        buttonBackground: CustomColors.primary,
        buttonText: CustomColors.tertiaryText,
        disabled: CustomColors.secondaryText,
        error: CustomColors.danger,
        textButtonColor: CustomColors.primaryText,
        hintColor: CustomColors.hintText,
        checkBoxColor: CustomColors.secondaryText,
        iconColor: CustomColors.primaryText,
        textFieldBorderColor: CustomColors.secondaryText,
        activeTextTabColor: CustomColors.primary,
        deActiveTextTabColor: CustomColors.secondaryText,
        indicatorTabColor: CustomColors.primary,
      );
}
